package warbots.entities.actions;


import java.awt.Point;

import warbots.entities.units.Unit;
import warbots.gameplay.Map;


/**
 * @author Ido Adler.
 */
public class HealAction extends Action
{
    
    private int _distance;
    
    /**
     * TODO: description
     * 
     * @param parent
     * @param name
     * @param distance
     */
    public HealAction(final Unit parent, final String name, final int distance)
    {
        super(parent, name);
        _damage = -_damage;
        _distance = distance;
        _price *= _distance;
    }
    
    public HealAction(final Unit parent, final String name) {
		this(parent,name,1);
	}

	/**
     * @see warbots.entities.actions.Action#execute(warbots.gameplay.Map,
     *      java.awt.Point)
     */
    @Override
    public boolean execute(final Map world, final Point target)
    {
        if (target.distance(_parent.getPosition()) <= _distance)
        {
            Unit friend = world._board[target.x][target.y].getUnit();
            if (friend != null)
            {
                friend.getHit(this);
                System.out.println(_parent.getName() + ":" + getName() + "->"
                    + friend.getName());
                return true;
            }
        }
        return false;
    }
    
}
